playwright xss tests for renderMarkdownSafe#151
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Playwright browser regression tests for the production Markdown sanitization path, a bare ChangesBrowser XSS validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Pytest
participant LiveServer
participant BrowserPage
participant renderMarkdownSafe
participant DOMPurify
Pytest->>LiveServer: start application
BrowserPage->>LiveServer: navigate to root page
BrowserPage->>renderMarkdownSafe: render XSS payload
renderMarkdownSafe->>DOMPurify: sanitize rendered Markdown
DOMPurify-->>BrowserPage: return sanitized DOM
BrowserPage->>BrowserPage: assert no execution or dangerous artifacts
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_xss_browser.py`:
- Around line 53-57: Update the safe-render test branch around
renderMarkdownSafe to track or wrap DOMPurify.sanitize before rendering, then
assert that it was called at least once after processing the vectors. Keep the
existing renderMarkdownSafe invocation and assertions, while ensuring the test
fails if sanitization is removed or throws and the escaped-text fallback handles
the inputs instead.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 22dcdf94-0e2f-4b7d-a0c6-644f83f2cfa3
📒 Files selected for processing (4)
.github/workflows/tests.ymlpyproject.tomltests/test_xss_browser.pytests/test_xss_sanitization.py
There was a problem hiding this comment.
Optional data: URI vector (app.js mentions it)
Closes #142
The grep tests in test_xss_sanitization.py only prove the source still mentions DOMPurify. they do not run the frontend. this adds a headless chromium test that loads a real page (marked + dompurify + app.js from base.html), calls renderMarkdownSafe, and drops the result into innerHTML the same way workspace does.
Four payloads from the issue: img onerror, script tag, javascript: link markdown, svg onload. we set window.__xssProbe and check the dom sink for leftover onerror, script nodes, javascript: hrefs, and svg onload. production pages ship with csp now, so inline handlers often will not fire even if markup slips through. the assertions target stripped markup, not alert dialogs. there is a negative control that runs bare marked.parse without sanitize and expects dangerous attributes to still show up in the tree.
playwright 1.50.0 is in dev deps. ci gets a ubuntu-only browser-xss job: install chromium with deps, pytest tests/test_xss_browser.py, then the existing unittest grep backstop. pyinstaller steps stay on the unittest matrix job.
locally: pip install -e ".[dev]", playwright install chromium, pytest tests/test_xss_browser.py. comment out DOMPurify.sanitize in renderMarkdownSafe and the safe-path tests should fail.
Summary by CodeRabbit
Bug Fixes
Tests